package com.lize.threaduse;

public class Homework02 {
    public static void main(String[] args) {
        T t = new T();
        Thread thread = new Thread(t);
        Thread thread1 = new Thread(t);
         thread.start();
         thread1.start();
    }
}
class T implements  Runnable{

    private  int money=10000;
//涉及多个线程共享资源所以使用RUnnable
public  void run()
{

//使用sychronized实现了线程同步
    while (true){
        synchronized (this){

        if(money<1000)
        {
            System.out.println("余额不足");
            break;
        }
        money-=1000;
        System.out.println(Thread.currentThread().getName()+"去除了1000 当前余额为="+money);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


}

}